3.2 - Finding what we want to do
Looking into dnSpy for something to change
As we learned in the lesson before, we can look into the game code using tools like dnSpy. So now we can develop another mod looking into it. This time we are gonna change the player health, stamina etc.
So, open up dnSpy and if not already load all the source code dll's as we did in the lesson before.
After that, search for the LocalPlayer
like the last time and, unlike before, instead of selecting
the FirstPersonCharacter, we will select the Vitals
entry.
As you can see, Vitals contains all the stuff related to the player health, stamina, rest, fullness etc. This means that if we get a reference of it, we can change all of this stuff.
If you scroll down a bit, you will see methods like SetHealth or SetStamina.
Those are the ones we will use to make the next mod. But before creating the mod project and start making the mod, let test the changes in game with UnityExplorer first, so we can be sure it's what we want to do and that it will work.
Testing what we want to change using UnityExplorer
So you can now boot the game, load into a savegame and open up UnityExplorer pressing F7.
Now go into the Object Search tab as we did with the first mod and in the Class filter
type LocalPlayer (we could also type Vitals directly but let not do it for now).
Hit search and select one of the results (they are the same).
Now, with the LocalPlayer window opened, scroll down or search for Vitals
.
Click on Inspect and you will get all the Vitals related stuff.
If you scroll down, you will find ours SetHealth and SetStamina methods we saw in dnSpy before.
Now, as in the first mod remake in UnityExplorer, click on evaluate on each method and type the appropriate values (e.g 50 for SetHealth and 10 for SetStamina). Now click evaluate on each of them to execute eachself and you will see the player health went to 50 and stamina to 10.
Now that we have confirmed these are the methods we need and that they work fine, we can start making the mod project.